package ACWing.TheNnderlyingAlgorithm.离散化;
//802. 区间和（最大状态超时思路可以了）
import java.util.*;

/**
 * @author :chenjie
 * @date :Created 2022/11/26 10:58
 */
public class TheIntervalSum {
    static class Pall{
         int l;
         int r;

        public Pall(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public String toString() {
            return "Pall{" +
                    "l=" + l +
                    ", r=" + r +
                    '}';
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Set<Integer> set=new HashSet<>();//去重
        Pall[]p=new Pall[n];//记录插入值
        for (int i = 0; i < n; i++) {
            p[i]=new Pall(sc.nextInt(),sc.nextInt());
            set.add(p[i].l);
        }
        Pall[]s=new Pall[m];//记录询问
        for (int i = 0; i < m; i++) {
            s[i]=new Pall(sc.nextInt(),sc.nextInt());
            set.add(s[i].l);
            set.add(s[i].r);
        }

        ArrayList<Integer> list=new ArrayList<>();

        for (Integer integer : set) {
            list.add(integer);
        }

        int[]sum=new int[list.size()];//前缀和

        list.sort(Comparator.naturalOrder());
        int[]arr=new int[list.size()];//将添加的值存入
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < n; j++) {
                if(list.get(i) ==p[j].l){
                    arr[i]=arr[i]+p[j].r;//注意重复在一点相加
                }
            }
            if(i==0){
                sum[i]=arr[i];
                continue;
            }
            sum[i]=sum[i-1]+arr[i];
        }
        for (int i = 0; i < m; i++) {
            int x=show(s[i].l,list);
            int y=show(s[i].r,list);
            if(x==0){
                System.out.println(sum[y]);
                continue;
            }
            System.out.println(sum[y]-sum[x-1]);
        }

    }
    public static int show(int x,ArrayList<Integer>list){
        int l=0,r=list.size()-1;
        while (l<r){
            int mid=l+r+1>>1;
            if(list.get(mid)<=x){
                l=mid;
            }else {
                r=mid-1;
            }
        }
        return l;
    }
}
